package com.macro.mall.demo.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.demo.service.HomeService;
import com.macro.mall.model.PmsBrand;
import com.macro.mall.model.PmsProduct;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *商品  管理
 */
@Tag(name = "DemoController", description = "商品管理示例接口")
@Controller
@RequestMapping("/brand")
public class BrandController {
    @Autowired
    private HomeService homeService;

    @Operation(summary = "根据编号查询品牌信息")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<PmsBrand> detail(@PathVariable("id") Long id) {
        return CommonResult.success(homeService.detail(id));
    }

    @Operation(summary = "获取品牌商品信息")
    @RequestMapping(value = "/productList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<CommonPage<PmsProduct>> list(@RequestParam("brandId") Integer brandId,
                                                     @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                     @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum ){
        List<PmsProduct> returnApplyList = homeService.list(brandId, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(returnApplyList));
    }

}
